<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>

  <div id="test"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <script type="text/babel">
    // 1. 创建组件
    class Like extends React.Component {

      constructor (props) {
        super(props);

        this.state = {
          toggle: true
        }

        // 使用bind() 更改自定义的方法的this指向
        this.handleClick = this.handleClick.bind(this);
      }

      handleClick() {
        // 这里的this指向 undefined 
        const toggle = !this.state.toggle;
        // this.state.setState = !this.state.setState // 不能更新更新某个状态
        this.setState({
          toggle
        })
      }

      render() {
        return <h1 onClick={this.handleClick}>{this.state.toggle ? '我喜欢你' : '你喜欢我'}</h1>
      }

      
    }
    // 2. 渲染组件到页面
    ReactDOM.render(<Like />, document.getElementById('test'))
  </script>
</body>

</html>